package com.yztc.youbadbad.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.youbadbad.R;
import com.yztc.youbadbad.bean.homepage.ContentBean;
import com.yztc.youbadbad.helper.BitmapCircleTransformation;
import com.yztc.youbadbad.helper.RecyclerViewAdapterHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 值得买的adapter
 * Created by Tiffany.V.Chou on 2016/11/16.
 */

public class ContentRecyclerAdapter extends RecyclerViewAdapterHelper<ContentBean> {


    public ContentRecyclerAdapter(Context context, List<ContentBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_recycler_deserve, parent, false);

        return new ViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        ContentBean contentBean = mList.get(position);
        ((ViewHolder) holder).title.setText(contentBean.getTitle());
        ((ViewHolder) holder).introduction.setText(contentBean.getIntroduction());
        ((ViewHolder) holder).nickName.setText(contentBean.getNick_name());
        ((ViewHolder) holder).likeNum.setText(contentBean.getLike_num());

        Glide.with(mContext).load(contentBean.getAvatar())
                .transform(new BitmapCircleTransformation(mContext))
                .into(((ViewHolder) holder).avatar);//头像

        Glide.with(mContext).load(contentBean.getPhone_head_pic())
                .into(((ViewHolder) holder).phoneHeadPic);//图片

    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.phone_head_pic)
        ImageView phoneHeadPic;
        @BindView(R.id.introduction)
        TextView introduction;
        @BindView(R.id.avatar)
        ImageView avatar;
        @BindView(R.id.nick_name)
        TextView nickName;
        @BindView(R.id.like_num)
        TextView likeNum;
        @BindView(R.id.title)
        TextView title;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
